<?php

namespace Drupal\shushengyuan\Schemas;

use Drupal\shusy_banner\Entity\ShusyBanner;
use Drupal\shusy_banner\Entity\ShusyBannerItem;

/**
 * @OA\Schema(
 *   schema="Banner",
 *   type="object",
 *   description="Banner"
 * )
 */
class Banner extends AbstractBaseModel {

  protected function getEntityType() {
    return 'shusy_banner';
  }

  protected function setValue() {
    if ($this->entity instanceof ShusyBanner) {
      $items = shusy_banner_item_load_multiple(FALSE, [
        'banner_id' => $this->entity->id,
        'status' => 1,
      ]);
      $list = [];
      foreach ($items as $item) {
        if ($item instanceof ShusyBannerItem) {
          $list[] = BannerItem::get($item->id);
        }
      }
      $value = $list;
      $this->merge($value);
    }
  }
}
